<?php

class Config_Ini_Factory {
	const CONFIG_DIR = '/config/'; 
	
	public static function factory($configName, $cache = false) {
		$path = BASE_DIR . self::CONFIG_DIR . $configName . '.ini';
		$localPath = BASE_DIR . self::CONFIG_DIR  . $configName . '.local.ini';
		
		if (!is_readable($path)) {
			throw new Exception("Cannot read $path file");
		}

		if ($cache) {
			$config = new Config_Ini_Cache($path, null, true);
		} else {
			$config = new Zend_Config_Ini($path, null, true);
		}
		// Merge site-specific config
		if (is_readable($localPath)) {
			if ($cache) {
				$config->merge(new Config_Ini_Cache($localPath));
			} else {
				$config->merge(new Zend_Config_Ini($localPath));
			}
		}
		$config->setReadOnly();
		return $config;
	}
}